package businesslogic.user;

import java.awt.Dialog;
import java.rmi.RemoteException;
import java.util.ArrayList;

import javax.swing.table.TableModel;

import dataService.userDataService.UserDataService;
import po.userpo.Student;
import po.userpo.Teacher;
import po.userpo.UserID;
import po.userpo.UserPO;
import useDatabase.java.getTable;
import Enum.Factor;
import Enum.ResultMessage;
import vo.Limitation;
import vo.uservo.LoginVO;
import Enum.UserRole;
import businesslogicservice.userblservice.SecurityBlService;

public class Security implements SecurityBlService{
 
	UserID userid;
	String password;
	UserRole role;
	
	public  Security(LoginVO vo){
		userid=vo.getUserID();
		password=vo.getPassword();
		role=vo.getUserRole();
	}
	

	@Override
	public boolean checkPassword() {
		// TODO Auto-generated method stub
		getTable table=new getTable();
		TableModel model = null;
		boolean ifRight=false;
		ArrayList<Limitation>  list = new ArrayList<Limitation>();
		try {
			Limitation limitation=new Limitation(Factor.UserID, userid.getID());
			list.add(limitation);
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		UserDataService userDataService=new UserDataService();
		if(role.equals(UserRole.student)){
		ArrayList<Student>  student=userDataService.getStuList(list);
		    if(student.size()>0){
		     if(student.get(0).getPassword().equals(this.password)&&student.get(0).getUserRole().equals(role)){
		    	 System.out.println(student.get(0).getPassword());
		    	 ifRight=true;
		     }
		    }
		}
		else {
			ArrayList<Teacher>  teacher=userDataService.getTchList(list);
			if(teacher.size()>0){
		     if(teacher.get(0).getPassword().equals(this.password)&&teacher.get(0).getUserRole().equals(role)){
		    	 ifRight=true;
		     }
			}
		}
		return ifRight;
	}

}
